home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / wrlib / wraster.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-09  |  11.3 KB  |  460 lines

  1. /*
  2.  *  Raster graphics library
  3.  * 
  4.  *  Copyright (c) 1997 ~ 2000 Alfredo K. Kojima
  5.  * 
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *  
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *  
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * Environment variables:
  23.  * 
  24.  * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
  25.  * gamma correction value. Must be  greater than 0
  26.  * Only for PseudoColor visuals.
  27.  * 
  28.  * Default:
  29.  * WRASTER_GAMMA 1/1/1
  30.  * 
  31.  * 
  32.  * If you want a specific value for a screen, append the screen number
  33.  * preceded by a hash to the variable name as in
  34.  * WRASTER_GAMMA#1
  35.  * for screen number 1
  36.  */
  37.  
  38. #ifndef RLRASTER_H_
  39. #define RLRASTER_H_
  40.  
  41.  
  42. /* version of the header for the library: 0.20 */
  43. #define WRASTER_HEADER_VERSION    20
  44.  
  45.  
  46. #include <X11/Xlib.h>
  47. #include <X11/Xutil.h>
  48.  
  49. #ifdef XSHM
  50. #include <X11/extensions/XShm.h>
  51. #endif
  52.  
  53.  
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif /* __cplusplus */
  57.  
  58. /* RBestMatchRendering or RDitheredRendering */
  59. #define RC_RenderMode         (1<<0)
  60.  
  61. /* number of colors per channel for colormap in PseudoColor mode */
  62. #define RC_ColorsPerChannel    (1<<1)
  63.  
  64. /* do gamma correction */
  65. #define RC_GammaCorrection    (1<<2)
  66.  
  67. /* visual id to use */
  68. #define RC_VisualID        (1<<3)
  69.  
  70. /* shared memory usage */
  71. #define RC_UseSharedMemory    (1<<4)
  72.  
  73. /* use default instead of best visual */
  74. #define RC_DefaultVisual    (1<<5)
  75.  
  76. /* filter type for smoothed scaling */
  77. #define RC_ScalingFilter    (1<<6)
  78.  
  79. /* standard colormap usage */
  80. #define RC_StandardColormap    (1<<7)
  81.  
  82.     
  83.     
  84.  
  85.     
  86.     
  87. /* std colormap usage/creation modes */
  88. enum {
  89.     RUseStdColormap,               /* default. fallbacks to RIgnore.. if 
  90.                     there is none defined */
  91.     RCreateStdColormap,
  92.     RIgnoreStdColormap
  93. };
  94.     
  95.  
  96.     
  97. typedef struct RContextAttributes {
  98.     int flags;
  99.     int render_mode;
  100.     int colors_per_channel;           /* for PseudoColor */
  101.     float rgamma;               /* gamma correction for red, */
  102.     float ggamma;               /* green, */
  103.     float bgamma;               /* and blue */
  104.     VisualID visualid;               /* visual ID to use */
  105.     int use_shared_memory;           /* True of False */
  106.     int scaling_filter;
  107.     int standard_colormap_mode;           /* what to do with std cma */
  108. } RContextAttributes;
  109.  
  110.  
  111. /*
  112.  * describes a screen in terms of depth, visual, number of colors
  113.  * we can use, if we should do dithering, and what colors to use for
  114.  * dithering.
  115.  */
  116. typedef struct RContext {
  117.     Display *dpy;
  118.     int screen_number;
  119.     Colormap cmap;
  120.     
  121.     RContextAttributes *attribs;
  122.  
  123.     GC copy_gc;
  124.  
  125.     Visual *visual;
  126.     int depth;
  127.     Window drawable;               /* window to pass for XCreatePixmap().*/
  128.                        /* generally = root */
  129.     int vclass;
  130.     
  131.     unsigned long black;
  132.     unsigned long white;
  133.  
  134.     int red_offset;               /* only used in 24bpp */
  135.     int green_offset;
  136.     int blue_offset;
  137.  
  138.     /* only used for pseudocolor and grayscale */
  139.  
  140.     XStandardColormap *std_rgb_map;    /* standard RGB colormap */
  141.     XStandardColormap *std_gray_map;   /* standard grayscale colormap */
  142.     
  143.     int ncolors;               /* total number of colors we can use */
  144.     XColor *colors;               /* internal colormap */
  145.     unsigned long *pixels;           /* RContext->colors[].pixel */
  146.  
  147.     struct {
  148.     unsigned int use_shared_pixmap:1;
  149.     unsigned int optimize_for_speed:1;
  150.     } flags;
  151. } RContext;
  152.  
  153.  
  154. typedef struct RColor {
  155.     unsigned char red;
  156.     unsigned char green;
  157.     unsigned char blue;
  158.     unsigned char alpha;
  159. } RColor;
  160.  
  161.  
  162. typedef struct RHSVColor {
  163.     unsigned short hue;               /* 0-359 */
  164.     unsigned char saturation;           /* 0-255 */
  165.     unsigned char value;           /* 0-255 */
  166. } RHSVColor;
  167.  
  168.  
  169.  
  170. typedef struct RPoint {
  171.     int x, y;
  172. } RPoint;
  173.  
  174.  
  175. typedef struct RSegment {
  176.     int x1, y1, x2, y2;
  177. } RSegment;
  178.  
  179.     
  180.  
  181. /* image formats */
  182. enum RImageFormat {
  183.     RRGBFormat,
  184.     RRGBAFormat
  185. };
  186.  
  187.  
  188. /*
  189.  * internal 24bit+alpha image representation
  190.  */
  191. typedef struct RImage {
  192.     unsigned char *data;           /* image data RGBA or RGB */
  193.     unsigned width, height;           /* size of the image */
  194.     enum RImageFormat format;
  195.     RColor background;               /* background color */
  196. } RImage;
  197.  
  198.  
  199. /*
  200.  * internal wrapper for XImage. Used for shm abstraction
  201.  */
  202. typedef struct RXImage {
  203.     XImage *image;
  204.  
  205.     /* Private data. Do not access */
  206. #ifdef XSHM
  207.     XShmSegmentInfo info;
  208.     char is_shared;
  209. #endif
  210. } RXImage;
  211.  
  212.  
  213. /* image display modes */
  214. enum {
  215.     RDitheredRendering = 0,
  216.     RBestMatchRendering = 1
  217. };
  218.  
  219.  
  220. /* smoothed scaling filter types */
  221. enum {
  222.     RBoxFilter,
  223.     RTriangleFilter,
  224.     RBellFilter,
  225.     RBSplineFilter,
  226.     RLanczos3Filter,
  227.     RMitchellFilter
  228. };
  229.  
  230.  
  231. /* note that not all operations are supported in all functions */
  232. enum {
  233.     RClearOperation,               /* clear with 0 */
  234.     RCopyOperation,
  235.     RNormalOperation,           /* same as combine */
  236.     RAddOperation,
  237.     RSubtractOperation
  238. };
  239.  
  240.  
  241. enum {
  242.     RAbsoluteCoordinates = 0,
  243.     RRelativeCoordinates = 1
  244. };
  245.  
  246.  
  247. enum {
  248.     RSunkenBevel    = -1,
  249.     RNoBevel        = 0,
  250.     RRaisedBevel    = 1    
  251. };
  252. /* bw compat */
  253. #define RBEV_SUNKEN    RSunkenBevel
  254. /* 1 pixel wide */
  255. #define RBEV_RAISED    RRaisedBevel
  256. /* 1 pixel wide on top/left 2 on bottom/right */
  257. #define RBEV_RAISED2    2
  258. /* 2 pixel width */
  259. #define RBEV_RAISED3    3
  260.  
  261. enum {
  262.     RHorizontalGradient = 2,
  263.     RVerticalGradient = 3,
  264.     RDiagonalGradient = 4
  265. };
  266. /* for backwards compatibility */
  267. #define RGRD_HORIZONTAL  RHorizontalGradient
  268. #define RGRD_VERTICAL     RVerticalGradient
  269. #define RGRD_DIAGONAL    RDiagonalGradient
  270.  
  271.  
  272.  
  273. /* error codes */
  274. #define RERR_NONE        0
  275. #define RERR_OPEN         1      /* cant open file */
  276. #define RERR_READ        2      /* error reading from file */
  277. #define RERR_WRITE        3      /* error writing to file */
  278. #define RERR_NOMEMORY        4      /* out of memory */
  279. #define RERR_NOCOLOR        5      /* out of color cells */
  280. #define RERR_BADIMAGEFILE    6      /* image file is corrupted or invalid */
  281. #define RERR_BADFORMAT        7      /* image file format is unknown */
  282. #define RERR_BADINDEX        8      /* no such image index in file */
  283.  
  284. #define RERR_BADVISUALID    16     /* invalid visual ID requested for context */
  285. #define RERR_STDCMAPFAIL    17     /* failed to created std colormap */
  286.     
  287. #define RERR_XERROR        127    /* internal X error */
  288. #define RERR_INTERNAL        128    /* should not happen */
  289.  
  290.  
  291. /*
  292.  * Returns a NULL terminated array of strings containing the
  293.  * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
  294.  * Do not free the returned data.
  295.  */
  296. char **RSupportedFileFormats(void);
  297.  
  298.  
  299. char *RGetImageFileFormat(char *file);
  300.  
  301. /*
  302.  * Xlib contexts
  303.  */
  304. RContext *RCreateContext(Display *dpy, int screen_number,
  305.              RContextAttributes *attribs);
  306.  
  307. void RDestroyContext(RContext *context);
  308.  
  309. Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
  310.  
  311. /*
  312.  * RImage creation
  313.  */
  314. RImage *RCreateImage(unsigned width, unsigned height, int alpha);
  315.  
  316. RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
  317.  
  318. RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
  319.                  Pixmap mask);
  320.  
  321. RImage *RLoadImage(RContext *context, char *file, int index);
  322.  
  323.  
  324. void RDestroyImage(RImage *image);
  325.  
  326. RImage *RGetImageFromXPMData(RContext *context, char **xpmData);
  327.  
  328. /*
  329.  * RImage storing
  330.  */
  331. Bool RSaveImage(RImage *image, char *filename, char *format);
  332.  
  333. /*
  334.  * Area manipulation
  335.  */
  336. RImage *RCloneImage(RImage *image);
  337.  
  338. RImage *RGetSubImage(RImage *image, int x, int y, unsigned width, 
  339.              unsigned height);
  340.  
  341. void RCombineImageWithColor(RImage *image, RColor *color);
  342.  
  343. void RCombineImages(RImage *image, RImage *src);
  344.  
  345. void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
  346.          unsigned height, int dx, int dy);
  347.  
  348. void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
  349.  
  350. void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy, 
  351.                    unsigned width, unsigned height, int dx, int dy,
  352.                    int opaqueness);
  353.  
  354. RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
  355.  
  356. RImage *RSmoothScaleImage(RImage *src, unsigned new_width, 
  357.               unsigned new_height);
  358.  
  359. RImage *RRotateImage(RImage *image, float angle);
  360.     
  361.  
  362. RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
  363.  
  364. RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
  365.                            RColor *color);
  366.  
  367. /*
  368.  * Drawing
  369.  */
  370. Bool RGetPixel(RImage *image, int x, int y, RColor *color);
  371.  
  372. void RPutPixel(RImage *image, int x, int y, RColor *color);
  373.  
  374. void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
  375.  
  376. void RPutPixels(RImage *image, RPoint *points, int npoints, int mode, 
  377.         RColor *color);
  378.  
  379. void ROperatePixels(RImage *image, int operation, RPoint *points, 
  380.             int npoints, int mode, RColor *color);
  381.  
  382. int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
  383.  
  384. int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
  385.          RColor *color);
  386.  
  387. void RDrawLines(RImage *image, RPoint *points, int npoints, int mode, 
  388.         RColor *color);
  389.  
  390. void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
  391.            int mode, RColor *color);
  392.  
  393. void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
  394.  
  395. void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
  396.               RColor *color);
  397.  
  398. /*
  399.  * Color convertion
  400.  */
  401. void RRGBtoHSV(RColor *color, RHSVColor *hsv);
  402. void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
  403.  
  404. /*
  405.  * Painting
  406.  */
  407. void RClearImage(RImage *image, RColor *color);
  408.  
  409. void RFillImage(RImage *image, RColor *color);
  410.     
  411. void RBevelImage(RImage *image, int bevel_type);
  412.  
  413. RImage *RRenderGradient(unsigned width, unsigned height, RColor *from, 
  414.             RColor *to, int style);
  415.  
  416.  
  417. RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, 
  418.                  int style);
  419.  
  420.  
  421.  
  422. /*
  423.  * Convertion into X Pixmaps
  424.  */
  425. int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
  426.  
  427. int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
  428.               Pixmap *mask, int threshold);
  429.  
  430.  
  431. /*
  432.  * misc. utilities
  433.  */
  434. RXImage *RCreateXImage(RContext *context, int depth,
  435.                unsigned width, unsigned height);
  436.  
  437. RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
  438.             unsigned width, unsigned height);
  439.  
  440. void RDestroyXImage(RContext *context, RXImage *ximage);
  441.  
  442. void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage, 
  443.         int src_x, int src_y, int dest_x, int dest_y,
  444.         unsigned width, unsigned height);
  445.     
  446. /* do not free the returned string! */
  447. const char *RMessageForError(int errorCode);
  448.  
  449. int RBlurImage(RImage *image);
  450.  
  451. /****** Global Variables *******/
  452.  
  453. extern int RErrorCode;
  454.  
  455. #ifdef __cplusplus
  456. }
  457. #endif /* __cplusplus */
  458.  
  459. #endif
  460.